<template>
	<view class="feed">
		
		<view class="add_txt">
			<text class="title">反馈标题</text>
			<up-input
			    placeholder="请输入内容"
			    border="surround"
			    v-model="ptvalue"
				class="con"
			  ></up-input>
		</view>
		
		<view class="add_txt">
			<text class="title">反馈内容</text>
			<u--textarea class="con" v-model="arvalue" count  placeholder="请输入内容" ></u--textarea>
		</view>
		
		<up-button type="primary" text="新增意见" @click="adddate"></up-button>
		
	    <view class="fe">
	    	<view class="feedda"  v-for="item in feedlist" :key="item.id">
	    		<text class="title same">{{item.title}}</text>
	    		<text class="content same">{{item.content}}</text>
	    		<text class="time same">{{item.createTime}}</text>
	    	</view>
	    </view>
		
	</view>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import {getfeedback,addfeeddate} from '../../../api/parkApi.js'
import {talklist} from '@/mock/park.js'

const feedlist= ref() //意见列表
const ptvalue= ref() //反馈标题
const arvalue= ref() //反馈内容


//点击新增
const adddate=async()=>{
	
	if(ptvalue.value==null ||arvalue.value==null){
		
		uni.showToast({
			title:'内容不能为空',
			icon:"error"
		})
		return;
	}

		let res = await addfeeddate({
		header:{
			"Authorization":uni.getStorageSync('token')
		},
		data:{
			title:ptvalue.value,
			content:arvalue.value
		}
	})
	if(res.code==200){
		uni.showToast({
			title:'提交成功'
		})
		
		uni.navigateTo({
			url:'/pages/park/feedback/feedback'
		})
	}else{
	//模拟数据
		let top ={
			id:talklist()[talklist().length-1]+1,
			title:ptvalue.value,
			content:arvalue.value,
			createTime:newTime()
		}
		
		feedlist.value.unshift(top)
	}
	console.log(feedlist.value);
}

//时间
const newTime=()=>{
 let date= new Date()
 let year=date.getFullYear()
 let mon=date.getMonth()+1
 let day =date.getDate()
 let hou=date.getHours()
 let min=date.getHours()
 let str= '-'
 return year+str+mon+str+day+' '+hou+':'+min
	
}


//获取反馈列表
const getfeedbackdata=async()=>{
	let res = await getfeedback({
		header:{
			"Authorization":uni.getStorageSync('token')
		}
	})
	if(res.code==200){
		feedlist.value=res.rows
	}else{
		//模拟数据
		
		feedlist.value=talklist()
	}
	console.log(feedlist.value);
}

onMounted(()=>{
	getfeedbackdata()
})
</script>
<style lang="scss">
.feed{
	padding: 4px 10px;
	
	.add_txt{
	 display: flex;
	 align-items: center;
	 margin: 14px 0px;
	 
	 .title{
		 font-size: 16px;
		 font-weight: 700;
		 margin-right: 10px;
		 flex: 1;
	 }
	 .con{
		 flex: 3;
	 }
	
	}

   .fe{
	   margin-top:18px;
	  .feedda{
	  	  display: flex;
	  	  flex-direction: column;
	  	  padding: 2px 8px;
	  	  margin: 8px 0px;
	  	  background-color: #dce7ec;
	  	  border-radius: 12px;
	  	  
	  	  .title{
	  		  font-size: 18px;
	  		  font-weight: 700; 
	  	  }
	  	  .time{
	  		   font-size: 14px;
	  		   color: #a7a7a7;
	  	  }
	  	  .same{
	  		  margin: 3px 0px;
	  	  }
	    } 
   } 

 
}
</style>
